import vlc
import time

def end_callback(event):
    print("Video playback finished.")

video_path = "video/234.mp4"
instance = vlc.Instance()
player = instance.media_player_new()

# 设置媒体文件路径
media = instance.media_new(video_path)
player.set_media(media)

# 注册事件管理器和回调函数
events = player.event_manager()
events.event_attach(vlc.EventType.MediaPlayerEndReached, end_callback)

# 开始播放
player.play()

try:
    # 等待视频播放结束或用户中断
    while True:
        time.sleep(1)
        if not player.is_playing():
            break
except KeyboardInterrupt:
    print("\nPlayback interrupted by user.")
finally:
    player.stop()
    print("Cleaned up resources.")